//定义一个全局变量Dep,用来记录当前watcher
let id = 0;
class Dep {
    constructor() {
        //定义唯一标识
        this.id = id++;
        //属性记住dep
        this.subs = [];
    }
    depend() {
        //让watcher记住dep
        //Dep.target===watcher(Dep.target就是当前watcher)
        //console.log(Dep.target);
        //debugger
        Dep.target.addDep(this);
    }
    //dep记住watcher
    addSub(watcher) {
        this.subs.push(watcher);
    }
    //通知方法
    notify() {
        this.subs.forEach(watcher => watcher.update())
    }
}
//全局的watcher的静态属性target来记录这个当前的watcher
Dep.target = null;

//向外暴露 记录watcher 方法
export function pushTarget(watcher) {
    Dep.target = watcher;
}
//向外暴露 删除watcher 方法
export function popTarget() {
    Dep.target = null;
}

//暴露全局watcher
export default Dep;